package com.panopset.sf.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;

import com.panopset.sf.FontManager;
import com.panopset.sf.Windoc;

/**
 * Font menu.
 * @author Karl Dinwiddie
 *
 */
public class FontMenu extends AbstractMenu {

	/**
	 * @param swingDoc SwingDoc.
	 */
	public FontMenu(final Windoc swingDoc) {
		super(swingDoc, "Font");
		suppressMnemonic();
	}

	@Override
	public void populateMenu(final JMenu menu) {
		for (final FontManager.Size size : FontManager.Size.values()) {
			JCheckBoxMenuItem mi = new JCheckBoxMenuItem(size.name());
			mi.addActionListener(new ActionListener() {
				public void actionPerformed(final ActionEvent e) {
					sd.sf.setFontSize(size);
				}
			});
			FontManager.getInstance().registerMenuComponent(mi);
			menu.add(mi);
		}
		FontManager.getInstance().registerMenuComponent(menu);
	}
}
